package design.principle;

/**
 * @program JavaBase
 * @description: 接口隔离原则
 * @author: zhanglu
 * @create: 2020-03-26 14:54:00
 */
public class InterfaceIsolation {

    public static void main(String[] args) {

//        AbstractSearcher searcher = new Searcher(new PettyGirl("张三"));
//
//        searcher.show();


        //采用接口隔离原则 改造 （美女：身材、气质）
        AbstractSearcher2 searcher2 = new Searcher2((IGoodBodyGirl) new PettyGirl2("李四"));
        searcher2.show();

    }

}

abstract class AbstractSearcher{

    protected IPettyGirl iPettyGirl;

    public AbstractSearcher(IPettyGirl iPettyGirl){
        this.iPettyGirl = iPettyGirl;
    }

    public abstract void show();

}

interface IPettyGirl{

    void goodLooking();

    void niceFigure();

    void greatTemperament();

}

class Searcher extends AbstractSearcher{


    public Searcher(IPettyGirl iPettyGirl) {
        super(iPettyGirl);
    }

    @Override
    public void show() {
        super.iPettyGirl.goodLooking();
        super.iPettyGirl.niceFigure();
        super.iPettyGirl.greatTemperament();
    }

}

class PettyGirl implements IPettyGirl{

    private String name;

    public PettyGirl(String name){
        this.name = name;
    }

    @Override
    public void goodLooking() {
        System.out.println(this.name + " - goodLooking");
    }

    @Override
    public void niceFigure() {
        System.out.println(this.name + " - niceFigure");
    }

    @Override
    public void greatTemperament() {
        System.out.println(this.name + " - greatTemperament");
    }
}

abstract class AbstractSearcher2{

    protected IGoodBodyGirl iGoodBodyGirl;
    protected IGreatTemperamentGirl iGreatTemperamentGirl;

    public AbstractSearcher2(IGoodBodyGirl iGoodBodyGirl){
        this.iGoodBodyGirl = iGoodBodyGirl;
    }

    public AbstractSearcher2(IGreatTemperamentGirl iGreatTemperamentGirl){
        this.iGreatTemperamentGirl = iGreatTemperamentGirl;
    }

    public abstract void show();

}


interface IGoodBodyGirl{

    void goodLooking();

    void niceFigure();

}

interface IGreatTemperamentGirl{

    void greatTemperament();

}

class Searcher2 extends AbstractSearcher2{

    public Searcher2(IGoodBodyGirl iGoodBodyGirl) {
        super(iGoodBodyGirl);
    }

    public Searcher2(IGreatTemperamentGirl iGreatTemperamentGirl) {
        super(iGreatTemperamentGirl);
    }

    @Override
    public void show() {
        if(iGoodBodyGirl != null){
            iGoodBodyGirl.goodLooking();
            iGoodBodyGirl.niceFigure();
        }
        if(iGreatTemperamentGirl != null){
            iGreatTemperamentGirl.greatTemperament();
        }
    }
}


class PettyGirl2 implements IGoodBodyGirl, IGreatTemperamentGirl{

    private String name;

    public PettyGirl2(String name){
        this.name = name;
    }

    @Override
    public void goodLooking() {
        System.out.println("PettyGirl2 - goodLooking");
    }

    @Override
    public void niceFigure() {
        System.out.println("PettyGirl2 - niceFigure");
    }

    @Override
    public void greatTemperament() {
        System.out.println("PettyGirl2 - greatTemperament");
    }
}


